#pragma once

#include "memory.hpp"

#include <cassert>
#include <string>
#include <iostream>
#include <cstdint>
#include <map>

using namespace std;

class Command{
public:
	uint16_t mask;
	uint16_t opcode;
	string name;
	void (*func)(void *data);
	void *(*dataRead)(uint16_t a);
	string (*dataPrettifier)(void *data);
	
	Command(uint16_t m = 0, uint16_t o = 0, string n = "", void (*f)(void *d) = NULL,
		void *(*r)(uint16_t a) = NULL, string (*p)(void *d) = NULL):
		mask(m), opcode(o), name(n), func(f), dataRead(r), dataPrettifier(p) {assert(m>=o);}

};

extern map <uint16_t, Command> CommandMap;

int analizeCommand(uint16_t a);
// int analizeCommand(){
	// return analizeCommand(GM.rw(PC));
// }
int executeCommand(uint16_t a);
// int executeCommand(){
	// return executeCommand(GM.rw(PC));
// }
int printCommand(uint16_t a);
// int printCommand(){
	// return printCommand(GM.rw(PC));
// }
void registerCommand(Command c);
void registerAllComands();